#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char* convert(char* s, int numRows)
{
    int len = strlen(s);
    int lon = 2 * numRows - 2;
    int gp = 0;
    if (len % lon)
    {
        gp = len / lon + 1;
    }
    else
    {
        gp = len / lon;
    }
    int numColumns = gp * (numRows - 1);
    char arr[10][10] = { 0 };
    int n = 0;
    int i = 0;
    int count = 0;
    for (n = 0; n < gp; n++)
    {
        for (i = 0; i < numRows && count < len; i++)
        {
            arr[i][n * (numRows - 1)] = s[i + n * gp];
            count++;
        }
        for (i = numRows; i < lon && count < len; i++)
        {
            arr[2 * numRows - i - 2][i - numRows + 1 + n * (numRows - 1)] = s[i + n * gp];
            count++;
        }
    }
    char ret[1000] = { 0 };
    int j = 0;
    int num = 0;
    for (i = 0; i < numRows; i++)
    {
        for (j = 0; j < numColumns; j++)
        {
            if (arr[i][j])
            {
                ret[num] = arr[i][j];
                num++;
            }
        }
    }
    return ret;
}
int main()
{
    char str[100] = "PAYPALISHIRING";
    int num = 4;
    printf("%s", convert(str, num));
    return 0;
}